package com.android.jay.lib_video.videoplayer.core;

import android.view.ViewGroup;

/**
 * Created by wzp on 2020/2/6 0006.
 * <p>
 * 描述  ：todo
 */
public class VideoAdContext implements VideoAdSlot.SDKSlotListener {

    private ViewGroup mParentView;
    private VideoAdSlot mAdSlot;
    //视频地址
    private String mInstance;
    private VideoAdContextInterface mListener;

    public VideoAdContext(ViewGroup mParentView, String mInstance) {
        this.mParentView = mParentView;
        this.mInstance = mInstance;
        init();
    }

    private void init() {
        if (mInstance != null) {
            mAdSlot = new VideoAdSlot(mInstance, this);
        } else {
            mAdSlot = new VideoAdSlot(null, null);
            if (mListener != null) {
                mListener.onVideoFailed();
            }
        }

    }

    public void destory() {
        mAdSlot.destory();
    }

    public void setResultListener(VideoAdContextInterface listener) {
        this.mListener = listener;
    }

    @Override
    public ViewGroup getAdParent() {
        return mParentView;
    }

    @Override
    public void onVideoLoadSuccess() {
        if (mListener != null){
            mListener.onVideoSuccess();
        }

    }

    @Override
    public void onVideoFailed() {
        if (mListener != null){
            mListener.onVideoFailed();
        }
    }

    @Override
    public void onVideoComplete() {
        if (mListener != null){
            mListener.onVideoComplete();
        }
    }

    public interface VideoAdContextInterface {
        void onVideoSuccess();

        void onVideoFailed();

        void onVideoComplete();
    }
}
